package com.tianbo.elfii.client.common;

import java.io.*;
import java.sql.*;
import java.net.*;
import java.awt.*;
import java.util.*;
import java.util.Timer;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.basic.BasicScrollBarUI;

import java.awt.image.*;
import javax.imageio.*;

import com.tianbo.elfii.client.common.ElfiiCommonUtil.FeedBackType;
import com.tianbo.elfii.client.common.wlanmanagement.WlanBaseDialog;
import com.tianbo.elfii.client.common.wlanmanagement.BaseDialogPane;
import com.tianbo.elfii.client.swingcomponentlib.unitcomponent.TitleLabel;

/**
 * <pre>
 <b>类功能描述：</b>
 * 
 * <pre>
 *      完成 Config-网络-WiFi 部分功能要求。
 * </pre>
 * 
 * @version 1.0.1
 * @author 高伟
 */

public class ElfiiCommonConfigNetWifi {
	JPanel configPanel;
	JPanel itemPanel;

	int infoBgStartX0;
	int infoBgStartY0;

	int dataChoiceIndex;

	boolean isAboutMachineSelected = false;
	boolean isWifiSettingSelected = false;

	JFrame mainFrame;
	ElfiiCommonRunInfo runInfo;
	
	ItemButtonPanel ipSettingPanel;
	ItemButtonPanel addWifiNetPanel;
	
	ItemButtonPanel selectedPanel;
	
	Vector<ApPanel> apPanelList;

	JScrollPane wifiListContainer;
	JPanel wifiListPane;

	ApPanel apPanel;
	
	public ItemButtonPanel selectedApPanel = null;
	public ApPanel connectedApPanel = null;

	final int Id_StaticIpSetting = -2;
	final int Id_AddWifiNet = -3;

	int selectedId = -100;

	JDialog addWifiConnectionWindow;

	JDialog staticIpSettingWindow;
	
	JPanel mainPanel;

	public void setRunInfo(ElfiiCommonRunInfo runInfo) {
		this.runInfo = runInfo;
		this.mainFrame = runInfo.getMainFrame();
	}

	public void dealBackButton() {
		mainFrame.getContentPane().removeAll();
		ElfiiCommonConfigNet configNet = new ElfiiCommonConfigNet();
		configNet.setRunInfo(runInfo);
		JPanel p = configNet.createViewPanel();
		mainFrame.getContentPane().setLayout(new BorderLayout());
		mainFrame.getContentPane().add(p, BorderLayout.CENTER);
		mainFrame.validate();
	}
	
	WlanStaticIpPane wlanStaticIpPane = null;

	public void dealOkButton() {

		if (selectedId == Id_AddWifiNet) {
			
			return;
			
//			selectedApPanel = addWifiNetPanel;
			
//			selectedApPanel.ap = new WlanAP();
//			selectedApPanel.ap.isCustomed = true;
//			
//			showCustomDialogPane();
		}

		else if (selectedId == Id_StaticIpSetting) {
			
			selectedApPanel = connectedApPanel;
			
			if(wlanStaticIpPane==null)
				return;
			
			wlanStaticIpPane.screenshot();
			wlanStaticIpPane.backPanel = mainPanel;
			mainFrame.setContentPane(wlanStaticIpPane);
			wlanStaticIpPane.showDialog();
			mainFrame.validate();
			
		}
		else
		{
			selectedApPanel = apPanelList.get(selectedId);
			
			showDialogPane();

		}
	}
	
	BaseDialogPane dialogPane;
	
	public void showCustomDialogPane(){
		WlanCustomConnectPane wlanCustomConnectPane = new WlanCustomConnectPane(this);
		wlanCustomConnectPane.backPanel = mainPanel;
		mainFrame.setContentPane(wlanCustomConnectPane);
		wlanCustomConnectPane.showDialog();
		mainFrame.validate();
	}
	
	public void showDialogPane(){
//		WlanAP selectedAP = selectedApPanel.ap;
//		if(selectedAP.getCurStat()==APSTAT.UNCONNECTED && selectedAP.getEncryptedStat()){
			dialogPane = new WlanConnectPane(this);
			dialogPane.screenshot();
			dialogPane.backPanel = mainPanel;
			mainFrame.setContentPane(dialogPane);
			dialogPane.showDialog();
			mainFrame.validate();
	}

	class AddWifiConnectionWindowPanel extends JPanel {

		BufferedImage infoImage;
		BufferedImage bgImg;

		public AddWifiConnectionWindowPanel() {
			File f;
			try {
				f = new File("resource-common/images/config/icons/tb.png");
				infoImage = ImageIO.read(f);

				int x0 = (int) mainFrame.getLocationOnScreen().getX();
				int y0 = (int) mainFrame.getLocationOnScreen().getY();
				Robot rbt = new Robot();
				bgImg = rbt
						.createScreenCapture(new Rectangle(x0, y0, 1024, 768));

			} catch (Exception e) {
				System.out.print(e);
			}
		}

		public void paintComponent(Graphics g) {
			super.paintComponent(g);
			Graphics2D g2 = (Graphics2D) g;
			g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
					RenderingHints.VALUE_ANTIALIAS_ON);
			g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
					0.4f));
			g2.drawImage(bgImg, null, 0, 0);
			g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
					1.0f));

			int rectX0 = 242, rectY0 = 220;
			int rectWidth = 530, rectHeight = 280;

			g2.setColor(Color.white);
			g2.fillRoundRect(rectX0, rectY0, rectWidth, rectHeight, 10, 10);
			g2.setColor(Color.black);
			g2.fillRoundRect(rectX0 + 5, rectY0 + 5, rectWidth - 10,
					rectHeight - 10, 10, 10);
			g2.drawImage(infoImage, null, rectX0 + 30, rectY0 + 20);
			g2.setColor(Color.gray);
			g2.drawLine(rectX0 + 20, rectY0 + 85, rectX0 + rectWidth - 20,
					rectY0 + 85);
			g2.fillRect(rectX0 + 5, rectY0 + rectHeight - 55, rectWidth - 10,
					50);

			g2.setFont(new Font(ElfiiCommonConstant.Font_Name, Font.PLAIN, 30));
			g2.setColor(Color.white);
			g2.drawString("Wi-Fi 连接设置", rectX0 + 185, rectY0 + 60);
			g2.setFont(new Font(ElfiiCommonConstant.Font_Name, Font.PLAIN, 20));
			g2.drawString("WAP 密码", rectX0 + 110, rectY0 + 150);

		}

		public Dimension getPreferredSize() {
			return (new Dimension(300, 100));
		}
	}

	class StaticIpSettingWindowPanel extends JPanel {

		BufferedImage infoImage;
		BufferedImage bgImg;

		public StaticIpSettingWindowPanel() {
			File f;
			try {
				f = new File("resource-common/images/config/icons/tb.png");
				infoImage = ImageIO.read(f);

				int x0 = (int) mainFrame.getLocationOnScreen().getX();
				int y0 = (int) mainFrame.getLocationOnScreen().getY();
				Robot rbt = new Robot();
				bgImg = rbt
						.createScreenCapture(new Rectangle(x0, y0, 1024, 768));

			} catch (Exception e) {
				System.out.print(e);
			}
		}

		public void paintComponent(Graphics g) {
			super.paintComponent(g);
			Graphics2D g2 = (Graphics2D) g;
			g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
					RenderingHints.VALUE_ANTIALIAS_ON);
			g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
					0.4f));
			g2.drawImage(bgImg, null, 0, 0);
			g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
					1.0f));

			int rectX0 = 242, rectY0 = 220;
			int rectWidth = 530, rectHeight = 280;

			g2.setColor(Color.white);
			g2.fillRoundRect(rectX0, rectY0, rectWidth, rectHeight, 10, 10);
			g2.setColor(Color.black);
			g2.fillRoundRect(rectX0 + 5, rectY0 + 5, rectWidth - 10,
					rectHeight - 10, 10, 10);
			g2.drawImage(infoImage, null, rectX0 + 30, rectY0 + 20);
			g2.setColor(Color.gray);
			g2.drawLine(rectX0 + 20, rectY0 + 85, rectX0 + rectWidth - 20,
					rectY0 + 85);
			g2.fillRect(rectX0 + 5, rectY0 + rectHeight - 55, rectWidth - 10,
					50);

			g2.setFont(new Font(ElfiiCommonConstant.Font_Name, Font.PLAIN, 24));
			g2.setColor(Color.white);
			g2.drawString("静态IP设置", rectX0 + 185, rectY0 + 60);
			g2.setFont(new Font(ElfiiCommonConstant.Font_Name, Font.PLAIN, 14));
			g2.drawString("IP地址", rectX0 + 110, rectY0 + 150);

		}

		public Dimension getPreferredSize() {
			return (new Dimension(300, 100));
		}
	}

	public void createConfigPanel() {

		JPanel settingsButton = new JPanel();
		JLabel settingsText = new TitleLabel("  Wi-Fi设置");
		settingsText.setFont(new Font(ElfiiCommonConstant.Font_Name, Font.PLAIN, 15));
		settingsText.setForeground(Color.white);
		settingsText.setHorizontalAlignment(SwingConstants.LEFT);
		settingsButton.setBackground(Color.gray);
		settingsButton.setLayout(new BorderLayout());
		settingsButton.add(BorderLayout.WEST,settingsText);
		
		
		JPanel wifiNetsButton = new JPanel();
		JLabel wifiNetsText = new TitleLabel("  Wi-Fi网络");
		wifiNetsText.setFont(new Font(ElfiiCommonConstant.Font_Name, Font.PLAIN, 15));
		wifiNetsText.setForeground(Color.white);
		wifiNetsText.setHorizontalAlignment(SwingConstants.LEFT);
		wifiNetsButton.setBackground(Color.gray);
		wifiNetsButton.setLayout(new BorderLayout());
		wifiNetsButton.add(BorderLayout.WEST,wifiNetsText);


		ipSettingPanel = new ItemButtonPanel("IP设置", "");
		ipSettingPanel.setFocusable(true);
		ipSettingPanel.setBackground(Color.black);
		ipSettingPanel.addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				setSelectButton(Id_StaticIpSetting);
			}
		});

		addWifiNetPanel = new ItemButtonPanel("添加Wi-Fi网络", "");
		addWifiNetPanel.setFocusable(true);
		addWifiNetPanel.setBackground(Color.black);
		addWifiNetPanel.addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				setSelectButton(Id_AddWifiNet);
			}
		});

		wifiListPane = new JPanel();
		wifiListPane.setBackground(Color.black);
		wifiListPane.setLayout(null);
		wifiListContainer = new JScrollPane(wifiListPane);

		wifiListContainer.getHorizontalScrollBar().setEnabled(false);
		wifiListContainer.getVerticalScrollBar().setPreferredSize(new Dimension(30,300));
		wifiListContainer.getVerticalScrollBar().setUI(new MyScrollBarUI());
		wifiListContainer.setBorder(null);

		configPanel = new JPanel();
		configPanel.setBackground(Color.black);
		configPanel.setLayout(null);

		configPanel.add(settingsButton);
		settingsButton.setBounds(0, 10, 1024, 23);

		configPanel.add(ipSettingPanel);
		ipSettingPanel.setBounds(0, 33, 1024, 63);
		configPanel.add(addWifiNetPanel);
		addWifiNetPanel.setBounds(0, 96, 1024, 63);

		configPanel.add(wifiNetsButton);
		wifiNetsButton.setBounds(0, 159, 1024, 23);

		configPanel.add(wifiListContainer);
		wifiListContainer.setBounds(0, 182, 1024, 378+wifiListContainer.getHorizontalScrollBar().getHeight());
		
		setWifiListPane();
		
	}
	
	public void setWifiListPane(){
		
		ElfiiCommonConfigUtil.scanSearchedWlan();
		
		ElfiiCommonConfigUtil.scanSavedWlan();

		apPanelList = new Vector<ApPanel>();
		
		int i = 0;
		
		Iterator iter = ElfiiCommonConfigUtil.searchedApList.entrySet().iterator();
		
		while(iter.hasNext()){
			
			 
			WlanAP ap = ((Map.Entry<String, WlanAP>)iter.next()).getValue();

			if(!ElfiiCommonConfigUtil.savedApList.isEmpty()){
				if(ElfiiCommonConfigUtil.savedApList.containsKey(ap.getSSID())){
					ap.setPassword(ElfiiCommonConfigUtil.savedApList.get(ap.getSSID()).getPassword());
					ap.setEncryptType(ElfiiCommonConfigUtil.savedApList.get(ap.getSSID()).getEncryptType());
					ap.setHiddenStat(ElfiiCommonConfigUtil.savedApList.get(ap.getSSID()).getHiddenStat());
					ap.setCurStat(APSTAT.SAVED);
					ap.setSavedStat(true);
				}
			}
			
			apPanel = new ApPanel(ap);
			
			if(ElfiiCommonConfigUtil.curConnectedAp!=null){
				if(apPanel.ap.getSSID().equals(ElfiiCommonConfigUtil.curConnectedAp.getSSID())){
					ElfiiCommonConfigUtil.curConnectedAp.setHiddenStat(apPanel.ap.getHiddenStat());
					ElfiiCommonConfigUtil.curConnectedAp.setEncryptType(apPanel.ap.getEncryptType());
					ElfiiCommonConfigUtil.curConnectedAp.setQuality(apPanel.ap.getQuality());
					apPanel = new ApPanel(ElfiiCommonConfigUtil.curConnectedAp);
				}
			}
			
			apPanelList.add(apPanel);
		}
		paintApPanelList();
//		wifiListPane.setPreferredSize(new Dimension(1024, 63*ElfiiCommonConfigUtil.searchedApList.size()));
	}
	
	public void paintApPanelList(){
		wifiListPane.removeAll();
		
		for(int i =0;i<apPanelList.size();i++){
			ApPanel apPanel = apPanelList.get(i);
			System.out.println(apPanel.ap.getSSID()+" "+apPanel.ap.getCurStat());
			if(apPanel.ap.getCurStat()==APSTAT.CONNECTING || apPanel.ap.getCurStat()==APSTAT.CONNECTED){
				apPanelList.remove(i);
				apPanelList.add(0, apPanel);
				connectedApPanel = apPanel;
				break;
			}
		}
		
		for(int i =0;i<apPanelList.size();i++){
			ApPanel apPanel = apPanelList.get(i);
			apPanel.setFocusable(true);
			apPanel.setBackground(Color.black);
			
			final int index = i;
			
			apPanel.addMouseListener(new MouseAdapter() {
				public void mousePressed(MouseEvent e) {
					setSelectButton(index);
				}
			});
			

			wifiListPane.add(apPanel);
			apPanel.setBounds(0, 63*index, 1024, 63);
		}
		wifiListPane.setPreferredSize(new Dimension(994, 63*apPanelList.size()));
		wifiListContainer.getVerticalScrollBar().setValue(0);
	}

	public void setSelectButton(int selectedId) {
		
    	if(this.selectedId==selectedId){
    		return;
    	}
		
		this.selectedId = selectedId;
		
		if(selectedPanel!=null)
		selectedPanel.setSelected(false);

		if (selectedId == Id_StaticIpSetting){
			selectedPanel = ipSettingPanel;
		}
		else if (selectedId == Id_AddWifiNet){
			selectedPanel = addWifiNetPanel;
		}
		else if(selectedId<apPanelList.size()){
			selectedPanel = apPanelList.get(selectedId);
		}
		

		if(selectedPanel!=null){
			selectedPanel.setSelected(true);
			ElfiiCommonUtil.playFeedbackAudio(FeedBackType.CLICK);
		}
	}

	class MyScrollBarUI extends BasicScrollBarUI {
		
		public MyScrollBarUI(){
			super();
		}

		@Override
		protected void paintThumb(Graphics g, JComponent c,
				Rectangle thumbBounds) {

			int w = thumbBounds.width;
			int h = thumbBounds.height;
			
			g.translate(thumbBounds.x, thumbBounds.y);
			// 绘制白色边框矩形
			// g.setColor(java.awt.Color.WHITE);
			g.drawRect(0, 0, w - 2, h - 2);
			// 用黑色填充矩形
			g.setColor(java.awt.Color.BLACK);
			g.fillRect(0, 0, w - 2, h - 2);

			// 绘制红色的线
			g.setColor(java.awt.Color.WHITE);
		
			// (1,1)到(1,h-2)的线（左边）
			g.drawLine(1, 1, 1, h - 2);
			// (2,1)到(w-3,1)的线（上边）
			g.drawLine(2, 1, w - 3, 1);

//			g.setColor(java.awt.Color.WHITE);
			// (2,h-2)到(w-2,h-2)的线（下边）
			g.drawLine(2, h - 2, w - 2, h - 2);
			// (w-2,1)到(w-2, h-3)的线（右边）
			g.drawLine(w - 2, 1, w - 2, h - 3);

			g.translate(-thumbBounds.x, -thumbBounds.y);
		}

		@Override
		protected void paintTrack(Graphics g, JComponent c,
				Rectangle trackBounds) {
			g.setColor(java.awt.Color.gray);
			g.fillRect(trackBounds.x, trackBounds.y, trackBounds.width,
					trackBounds.height);
		}
		
		@Override
		protected javax.swing.JButton createDecreaseButton(int orientation) {
			JButton btn = new JButton();
			btn.setPreferredSize(new Dimension(0,0));
			return btn;
		}
		
		@Override
		protected javax.swing.JButton createIncreaseButton(int orientation) {
			JButton btn = new JButton();
			btn.setPreferredSize(new Dimension(0,0));
			return btn;
		}
	}

	class ItemButtonPanel extends JPanel {
		

		public WlanAP ap = null;
		
		BufferedImage selectedBgImage;

		BufferedImage lineImage;

		BufferedImage img2;

		BufferedImage gaoImg;

		String str1;
		String str2;
		boolean isSelected;

		Color defaultColor;
		
		public ItemButtonPanel(){}

		public ItemButtonPanel(String str1, String str2) {
			this.str1 = str1;
			this.str2 = str2;
			File f = null;
			try {
				f = new File("resource-common/images/config/icons/tc_butbg.png");
				selectedBgImage = ImageIO.read(f);
				f = new File("resource-common/images/config/icons/tb_bg.png");
				img2 = ImageIO.read(f);
				f = new File("resource-common/images/config/icons/line.png");
				lineImage = ImageIO.read(f);
			} catch (Exception e) {
				System.out.print(e + "   " + f);
			}
		}

		public void setSelected(boolean isSelected) {
			this.isSelected = isSelected;
			repaint();
		}

		public void paintComponent(Graphics g) {
			super.paintComponent(g);

			Graphics2D g2 = (Graphics2D) g;
			g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
					RenderingHints.VALUE_ANTIALIAS_ON);
			g2.setColor(Color.black);
			g2.fillRect(0, 0, 1024, 63);
			if (isSelected) {
				g2.drawImage(selectedBgImage, null, 0, 0);
				g2.setColor(ElfiiCommonConstant.Elfii_Blue);
			} else {
				g2.setColor(Color.white);
			}

			g2.setFont(new Font(ElfiiCommonConstant.Font_Name, Font.PLAIN, 20));
			g2.drawString(str1, 20, 35);
			g2.setFont(new Font(ElfiiCommonConstant.Font_Name, Font.PLAIN, 12));
			g2.drawString(str2, 20, 50);
			g2.drawImage(lineImage, null, 0, 62);
		}

		public Dimension getPreferredSize() {
			return (new Dimension(1024, 63));
		}
	}
	
	public class ApPanel extends ItemButtonPanel {
		
		
		BufferedImage qualitySelectedImg;
		BufferedImage qualityUnselectedImg;
		
		public ApPanel(WlanAP ap) {
			
			this.ap = ap;
			
			String statStr = "";
			
			if(ap.getCurStat()==APSTAT.CONNECTED){
				statStr="已连接";
			}
			else if(ap.getCurStat()==APSTAT.SAVED){
				statStr="已保存";
			}
			else if(ap.getCurStat()==APSTAT.NOSERVICE){
				statStr="已连接（无服务器访问）";
			}
			else{
				statStr="未连接";
			}
			
			this.str1 = ap.getSSID();
			this.str2 = statStr;
			
			File f = null;
			try {
				f = new File("resource-common/images/config/icons/tc_butbg.png");
				selectedBgImage = ImageIO.read(f);
				f = new File("resource-common/images/config/icons/tb_bg.png");
				img2 = ImageIO.read(f);
				f = new File("resource-common/images/config/icons/line.png");
				lineImage = ImageIO.read(f);
				
				
			} catch (Exception e) {
				System.out.print(e + "   " + f);
			}
			
			setQualityIcon();
		}
		
		public void setQualityIcon(){
			File f = null;
			try{
				float apQuality = ap.getQuality();
				
				if(apQuality<25){
					if(ap.getEncryptedStat()){
						f = new File("resource-common/images/config/ss_22_t.png");
						qualitySelectedImg = ImageIO.read(f);
						
						f = new File("resource-common/images/config/ss_22.png");
						qualityUnselectedImg = ImageIO.read(f);
					}
					else{
						f = new File("resource-common/images/config/ss_18_t.png");
						qualitySelectedImg = ImageIO.read(f);
						
						f = new File("resource-common/images/config/ss_18.png");
						qualityUnselectedImg = ImageIO.read(f);
					}
				}
				else if(apQuality>=25 && apQuality<50){
					if(ap.getEncryptedStat()){
						f = new File("resource-common/images/config/ss_21_t.png");
						qualitySelectedImg = ImageIO.read(f);
						
						f = new File("resource-common/images/config/ss_21.png");
						qualityUnselectedImg = ImageIO.read(f);
					}
					else{
						f = new File("resource-common/images/config/ss_17_t.png");
						qualitySelectedImg = ImageIO.read(f);
						
						f = new File("resource-common/images/config/ss_17.png");
						qualityUnselectedImg = ImageIO.read(f);
					}
				}
				else if(apQuality>=50 && apQuality<75){
					if(ap.getEncryptedStat()){
						f = new File("resource-common/images/config/ss_20_t.png");
						qualitySelectedImg = ImageIO.read(f);
						
						f = new File("resource-common/images/config/ss_20.png");
						qualityUnselectedImg = ImageIO.read(f);
					}
					else{
						f = new File("resource-common/images/config/ss_16_t.png");
						qualitySelectedImg = ImageIO.read(f);
						
						f = new File("resource-common/images/config/ss_16.png");
						qualityUnselectedImg = ImageIO.read(f);
					}
				}
				else{
					if(ap.getEncryptedStat()){
						f = new File("resource-common/images/config/ss_19_t.png");
						qualitySelectedImg = ImageIO.read(f);
						
						f = new File("resource-common/images/config/ss_19.png");
						qualityUnselectedImg = ImageIO.read(f);
					}
					else{
						f = new File("resource-common/images/config/ss_15_t.png");
						qualitySelectedImg = ImageIO.read(f);
						
						f = new File("resource-common/images/config/ss_15.png");
						qualityUnselectedImg = ImageIO.read(f);
					}
				}
			}
			catch(Exception e){}
		}


		public void paintComponent(Graphics g) {
			super.paintComponent(g);

			Graphics2D g2 = (Graphics2D) g;
			
			if (isSelected) {
				g2.drawImage(qualitySelectedImg, null, 940, 17);
			} else {
				g2.drawImage(qualityUnselectedImg, null, 940, 17);
			}
			
		}
	}


	public JPanel createViewPanel() {
		mainPanel = new JPanel(new BorderLayout());
		JButton okButton = new JButton();
		okButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dealOkButton();
				ElfiiCommonUtil.playFeedbackAudio(FeedBackType.CLICK);
			}
		});

		JButton backButton = new JButton();
		backButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dealBackButton();
				ElfiiCommonUtil.playFeedbackAudio(FeedBackType.CLICK);
			}
		});

		JButton homeButton = runInfo.createHomeButton();

		JPanel topPanel = ElfiiCommonUtil.createTopPanel("系统设置", backButton,
				homeButton);
		JPanel bottomPanel = ElfiiCommonUtil
				.createBottomPanelLevelSelect(okButton);
		createConfigPanel();
		mainPanel.setLayout(null);
		mainPanel.setBackground(Color.black);
		mainPanel.add(topPanel);
		topPanel.setBounds(0, 0, 1024, 100);
		mainPanel.add(bottomPanel);
		bottomPanel.setBounds(0, 668, 1024, 100);
		mainPanel.add(configPanel);
		configPanel.setBounds(0, 101, 1024, 560);
		Timer timer = new Timer();
		
		timer.schedule(new TimerTask(){
			public void run() {
				// TODO Auto-generated method stub
				initNextPanel();
			}
		}, 100);
		

		return mainPanel;
	}
	
	public void initNextPanel(){
		wlanStaticIpPane = new WlanStaticIpPane(this);
	}
}
